#!/usr/bin/ruby
# -*- ruby -*-
#
# http://www.reddit.com/r/dailyprogrammer/comments/12csm4/10302012_challenge_109_intermediate/

require 'set'

class Fixnum
    def palindrome?
        return self.to_s == self.to_s.reverse
    end
end

# Defaults!
a1, a2 = [10, 11]
b1, b2 = [10, 11]

a1, a2, b1, b2 = ARGV.map { |i| i.to_i } if ARGV.size == 4

(a1 .. a2).to_a.product((b1 .. b2).to_a).inject(Set.new) do |s, (a, b)|
    (a * b).palindrome? ? s << [a, b].sort : s
end.each do |(a, b)|
    puts "#{a}, #{b} => #{a * b}"
end
